package com.asset.salesforce.converter;


import com.asset.salesforce.domain.Lead;
import com.asset.salesforce.enums.INDUSTRY;
import com.asset.salesforce.enums.LEADSOURCE;
import com.asset.salesforce.enums.LEADSTATUS;
import com.asset.salesforce.enums.RATING;
import com.asset.salesforce.form.LeadForm;

public class LeadConverter {
	public LeadForm leadToLeadFormConverter(Lead lead) {
		
		LeadForm leadForm =new LeadForm();
		if(lead.getCompanyName()!=null){
			leadForm.setCompanyName(lead.getCompanyName());	
		}
		if(lead.getId()!=null){
			leadForm.setLeadId(lead.getId());	
		}
		if(lead.getfName()!=null){
			leadForm.setfName(lead.getfName());
		}
		if(lead.getlName()!=null){
			leadForm.setlName(lead.getlName());
		}
		
		if(lead.getLeadOwner().getfName()!=null){
			leadForm.setOwnerName(lead.getLeadOwner().getfName());
		}
		if(lead.getLeadOwner().getId()!=null){
			leadForm.setOwnerId(lead.getLeadOwner().getId());
		}
		
		if(lead.getTitle()!=null){
			leadForm.setTitle(lead.getTitle());
		}
		if(lead.getEmail()!=null){
			leadForm.setEmail(lead.getEmail());
		}
		if(lead.getPhone()!=null){
			leadForm.setPhone(lead.getPhone());
		}
		if(lead.getMobile()!=null){
			leadForm.setMobile(lead.getMobile());
		}
		if (lead.getStreet()!=null){
			leadForm.setStreet(lead.getStreet());
		}
		if(lead.getZipCode()!=null){
			leadForm.setZipCode(lead.getZipCode());
		}
		
		if(lead.getCountry()!=null){
			leadForm.setCountry(lead.getCountry().getId());
		}
		if(lead.getCity()!=null){
			leadForm.setCity(lead.getCity().getId());
		}
		if(lead.getState()!=null){
			leadForm.setState(lead.getState());
		}
		if(lead.getWebSite()!=null){
			leadForm.setWebsite(lead.getWebSite());
		}
		if(lead.getNumOfEmp()!=null){
			 
			leadForm.setEmpNum(lead.getNumOfEmp());
		}
		if(lead.getAnnualRevenue()!=null){
			leadForm.setAnnualRevenue(lead.getAnnualRevenue());
		}
		if(lead.getDescription()!=null){
			leadForm.setDescription(lead.getDescription());
		}
		if(lead.getInOutBound()!=null){
			leadForm.setInOutBound(lead.getInOutBound());
		}
		if(lead.getCarsNum()!=null){
			leadForm.setCarsNum(lead.getCarsNum());
		}
//		if(lead.getLeadStatus() != null){
//			leadForm.setLeadStatus(lead.getLeadStatus());
//		}
		if(lead.getIsConverted() != null){
			leadForm.setIsConverted(lead.getIsConverted());
		}
		if(lead.getCategory() != null && !lead.getCategory().equalsIgnoreCase("")){
			leadForm.setCategory(lead.getCategory());
		}
		String intdustry = lead.getIndustry();
		if(intdustry != null){
		leadForm.setIndustry(intdustry);
		}else{
			leadForm.setIndustry(new String(""));
		}
		//rating
		RATING[] ratings = RATING.values();
		Integer rating = 0;
		for(int i =0 ; i<ratings.length;i++){
			if(ratings[i].getName().equals((String)lead.getRating())){
				rating = i;
			}
		}
		leadForm.setRating(rating);
		//leadsources
//		LEADSOURCE[] leadSources = LEADSOURCE.values();
//		Integer leadsource=0;
//		for(int i =0 ; i<leadSources.length;i++){
//			if(leadSources[i].getName().equals((String)lead.getLeadSource())){
//				leadsource = i;
//			}
//		}
//	//	leadForm.setLeadSource(leadsource);
		//lead status
		LEADSTATUS[] leadStatus = LEADSTATUS.values();
		Integer status=0;
		for(int i =0 ; i<leadStatus.length;i++){
			if(leadStatus[i].getName().equals((String)lead.getLeadStatus())){
				status = i;
			}
		}
		if(lead.getLeadSource()!= null&&!(lead.getLeadSource().equalsIgnoreCase(""))){
			leadForm.setLeadSource(lead.getLeadStatus());
		}
		
		
		
		return leadForm;
	}
}
